package com.itheima.manager.service.imp;

import com.itheima.manager.mapper.ContactMapper;
import com.itheima.manager.pojo.Contact;
import com.itheima.manager.service.IAddService;
import com.itheima.manager.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

public class AddServiceImp implements IAddService {
    @Override
    public boolean add(Contact contact) {

        SqlSession session = SqlSessionUtil.getSession();
        ContactMapper mapper = session.getMapper(ContactMapper.class);

        Contact c1 = mapper.selectAllByName(contact.getName());

        if(c1==null){
            mapper.add(contact);
            session.commit();
            session.close();
        }

        return c1==null;


    }
}
